function $(selector){
    return document.querySelector(selector)
}
axios.get('https://ty.php800.cn/api/member/search.php',{
    params:{
        id:JSON.parse(localStorage.user).id
    },
    headers:{
        TOKEN: localStorage.getItem('token'),
        SAT:'1234567'
    }
}).then((res)=>{
    let {nickname,phone,email,gender,registrationtime,useravatar}=res.data.member[0]
    document.querySelector('.personal .img img').src=useravatar
    $('.personal .nickname').innerHTML=nickname
    $('.personal .phone').innerHTML=phone
    $('.personal .email').innerHTML=email
    $('.personal .gender').innerHTML=gender==1?'男':'女'
    
    let date=new Date(parseInt(registrationtime))
    date=date.getFullYear()+'年'+addzero(date.getMonth()+1)+'月'+addzero(date.getDate())+'日&nbsp;&nbsp;&nbsp;&nbsp;'+addzero(date.getHours())+':'+addzero(date.getMinutes())+":"+addzero(date.getSeconds())
    $('.personal .registrationtime').innerHTML=date
})
let redact=document.getElementById('redact'),
file=document.getElementById('file');
redact.onclick=function(){
    file.click();
}
file.onchange=function(){
    let read=new FileReader();
    read.readAsDataURL(this.files[0])
    read.onload=function(e){
        let formdata=new FormData()
        formdata.append('userid',JSON.parse(localStorage.user).id)
        formdata.append('base64',read.result)
        axios.post('https://ty.php800.cn/api/member/avatar.php',formdata,{
            headers:{
                SAT:'1234567'
            }
        }).then(()=>{
            location.reload()
        })
    }
}
axios.get('https://ty.php800.cn/api/article/list.php',{
    params:{
        userid:JSON.parse(localStorage.user).id
    },
    headers:{
        SAT:'1234567'
    }
}).then((res)=>{
    let list=document.querySelector('.correlation .list')
    for(let i=0;i<res.data.blogs.length;i++){
        let{body,datetime,userid}=res.data.blogs[i];
        let date=new Date(parseInt(datetime))
        date=date.getFullYear()+'年'+addzero(date.getMonth()+1)+'月'+addzero(date.getDate())+'日&nbsp;&nbsp;&nbsp;&nbsp;'+addzero(date.getHours())+':'+addzero(date.getMinutes())+":"+addzero(date.getSeconds())
        let li=document.createElement('li')
        li.classList.add('row')
        axios.get('https://ty.php800.cn/api/article/getuser.php',{
            params:{
                userid:userid
            },
            headers:{
                // TOKEN: localStorage.getItem('token'),
                SAT:'1234567'
            }
        }).then((res)=>{
            li.innerHTML=`
                <div class="profile_photo" style="background: url(${res.data.member[0].useravatar});background-size: cover;background-position: center;"></div>
                <div class="right">
                    <div class="name">${res.data.member[0].nickname}</div>
                    <div class="time">${date}</div>
                    <div class="main">${body}</div>
                </div>
            `
        })
        list.appendChild(li)
    }
})
function addzero(date){
    return date<10?'0'+date:date
}